package es.daw.ejercicio3.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;

public class ConnectionFactory {

	private ResourceBundle rc;
	private static ConnectionFactory connectionFactory = null;

	private ConnectionFactory() {
		try {

			rc = ResourceBundle.getBundle("connection.properties");
			Class.forName(rc.getString("connection.driverClassName"));

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public Connection getConnection() throws SQLException {

		String connectionUrl = rc.getString("connection.url");
		String dbUser = rc.getString("connection.user");
		String dbPwd = rc.getString("connection.password");
		return DriverManager.getConnection(connectionUrl, dbUser, dbPwd);
	}

	public static ConnectionFactory getInstance() {
		if (connectionFactory == null) {
			connectionFactory = new ConnectionFactory();
		}
		return connectionFactory;
	}
}
